@extends('layout.master')

@section('title')
   Administrator Page - Add Product
@stop

@section('username')
   {{ Auth::user()->userName }} 
@stop

@section('header')
    @parent
@stop

@section('side-menu')
    @parent
@stop

@section('content')

    <h3> Add New Product </h3> <hr />

<form id='AddForm' method="post" action="/api/product/add">
    <label> Supplier </label> 
    <select size="1" name="supplier">
        @foreach($suppliers as $supplier)
            <option value={{$supplier->id}}> {{ $supplier->supplierName }} </option>
        @endforeach
    </select> <br /> <br /> 

    <label> Category </label> 
    <select size="1" name="category">
        @foreach($categories as $category)
            <option value={{$category->id}}> {{ $category->categoryName }} </option>
        @endforeach
    </select> <br /> <br />

    <label> Product Name </label>
    <input type="text" name="productname" id="productname"/> 

    <label> Cost Price </label>
    <input type="text" name="costprice" id="costprice"/>

    <label> Retail Price </label>
    <input type="text" name="retailprice" id="retailprice"/>      

    <label> Quantity </label>
    <input type="text" name="quantity" id="quantity"/>  <br />

    <input type="submit" id="add" value="Add Product" class="btn btn-success" />   <input type="submit" id="clear" value="Clear Form" class="btn btn-danger" />    
</form>
@stop

@section('scripts')
	<script type="text/javascript">
		
			
			jQuery(function(){
                jQuery("#productname").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "Please enter the Required field"
                });

                jQuery("#costprice").validate({
                    expression: "if (VAL < 0) return false; else return true;",
                    message: "Please enter a value greater then 0"
                });

                jQuery("#retailprice").validate({
                    expression: "if (VAL < 0) return false; else return true;",
                    message: "Please enter a value greater then 0"
                });

                jQuery("#quantity").validate({
                    expression: "if (VAL < 0) return false; else return true;",
                    message: "Please enter a value greater then 0"
                });

                jQuery("#costprice").validate({
                    expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
                    message: "Please enter a valid number"
                });
                jQuery("#retailprice").validate({
                    expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
                    message: "Please enter a valid number"
                });
                jQuery("#quantity").validate({
                    expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
                    message: "Please enter a valid number"
                });
                
				jQuery('.AdvancedForm').validated(function(){
					alert("Use this call to make AJAX submissions.");
				});
            });

        $('#clear').click(function(e) {

            e.preventDefault();
            
            $('#AddForm')[0].reset();
            $('#AddForm input:first').focus();
        });
	</script>
@stop


